package cn.supermarket.controller;

import cn.supermarket.pojo.dto.StockCheckAddDTO;
import cn.supermarket.pojo.dto.StockCheckUpdateDTO;
import cn.supermarket.pojo.vo.StockCheckDetailsVo;
import cn.supermarket.pojo.vo.StockDetailedVO;
import cn.supermarket.service.iservice.ICheckStockService;
import cn.supermarket.web.JsonPage;
import cn.supermarket.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.time.LocalDateTime;
import java.util.Date;

@RestController
@RequestMapping("/check")
@Slf4j
@Api(tags = "库存清点")
public class StockCheckController extends BaseController {
    @Autowired
    private ICheckStockService checkStockService;
    //录入库存信息
    @PostMapping("/add")
    @ApiOperation("录入库存信息")
    public JsonResult<Void> addNew(StockCheckAddDTO stockCheckAddDTO){
        System.out.println("添加controller");
        checkStockService.addInfo(stockCheckAddDTO);
        return JsonResult.ok();    }

    @GetMapping("/select")
    @ApiOperation(("查询仓库列表"))
    public JsonResult<JsonPage<StockCheckDetailsVo>> stockList(Integer pageNum, Integer pageSize, Date date){
        JsonPage<StockCheckDetailsVo> jsonPage=checkStockService.selectListByDate(pageNum,pageSize,date);
        return JsonResult.ok(jsonPage);
    }

//    @PostMapping("/update")
//    @ApiOperation("修改仓库信息")
//    public  JsonResult<Void> updateByProductId( StockCheckUpdateDTO stockCheckUpdateDTO){
//        checkStockService.updateRecordByProductId(stockCheckUpdateDTO);
//        return JsonResult.ok();
//    }

    @PostMapping("/detail")
    @ApiOperation("仓库信息详情")
    public JsonResult<StockCheckDetailsVo> stockDetail( Long productId){
        StockCheckDetailsVo stockCheckDetailsVo = checkStockService.selectDetailsByProductId(productId);
        return JsonResult.ok(stockCheckDetailsVo);
    }

    @PostMapping("/delete")
    @ApiOperation("删除仓库录入信息")
    public JsonResult<Void> deleteByproductId(Long productId){
        checkStockService.deleteByProductId(productId);
        return JsonResult.ok();
    }


}
